﻿using EYangFramework.Common.Ninject;
using log4net;
using log4net.Config;
using log4net.Repository;
using System;
using System.IO;

namespace EYangFramework.Common.Logger
{
    [AutoBind(IsSington = true)]
    public class LogHelper
    {
        ILoggerRepository repository = LogManager.CreateRepository("EYangFrameworkRepository");
        ILog log;
        public LogHelper()
        {
            XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
            log = LogManager.GetLogger(repository.Name, "EYangFrameworkLogger");
        }
        public void Log(CustomLogInfo customLogInfo)
        {
            switch (Enum.Parse(typeof(LogLevel), customLogInfo.LogLevel))
            {
                case LogLevel.Debug:
                    log.Debug(customLogInfo);
                    break;
                case LogLevel.Info:
                    log.Info(customLogInfo);
                    break;
                case LogLevel.Warning:
                    log.Warn(customLogInfo);
                    break;
                case LogLevel.Error:
                    log.Error(customLogInfo);
                    break;
            }
        }
    }
}
